package cn.ekuma.epos.module;

import java.util.Collection;

import net.xeoh.plugins.base.PluginManager;
import net.xeoh.plugins.base.util.PluginManagerUtil;

import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.I_Session;
import com.openbravo.pos.base.BeanFactoryException;

import cn.ekuma.data.dao.I_DataLogic;
import cn.ekuma.epos.datalogic.I_CustomerDebtProcesser;
import cn.ekuma.epos.datalogic.I_DataLogicAdmin;
import cn.ekuma.epos.datalogic.I_DataLogicCustomers;
import cn.ekuma.epos.datalogic.I_DataLogicERP;
import cn.ekuma.epos.datalogic.I_DataLogicReceipts;
import cn.ekuma.epos.datalogic.I_DataLogicSystem;
import cn.ekuma.epos.datalogic.I_ProductRecommend;
import cn.ekuma.epos.datalogic.businesslogic.OrderProcessManager;
import cn.ekuma.epos.datalogic.businesslogic.orderprocess.I_OrderProcess;
import cn.ekuma.epos.datalogic.businesslogic.orderprocess.I_OrderProcessFlow;
import cn.ekuma.epos.datalogic.businesslogic.orderprocess.I_ProcessManager;
import cn.ekuma.epos.datalogic.define.DataLogicAdmin;
import cn.ekuma.epos.datalogic.define.DataLogicCustomers;
import cn.ekuma.epos.datalogic.define.DataLogicERP;
import cn.ekuma.epos.datalogic.define.DataLogicReceipts;
import cn.ekuma.epos.datalogic.define.DataLogicSystem;
import cn.ekuma.rabbit.ModelManager;
import cn.ekuma.rabbit.imp.AbstractModel;
import cn.ekuma.security.datalogic.I_DataLogicSecurity;

public class DefaultDataLogicModel extends AbstractModel {
	
	public final static String NAME="cn.ekuma.epos.module.DefaultDataLogicModel";

	protected  I_DataLogicERP dlERP;
	protected  I_DataLogicReceipts dlReceipts;
	protected  I_DataLogicSystem dlSystem;
	protected  I_DataLogicAdmin dlAdmin;
	protected  I_DataLogicCustomers dlCustomers;
	I_ProcessManager processManager;
	
	@Override
	public String getModelName() {
		return NAME;
	}

	@Override
	public String getModelDescription() {
		return "the base datalogic default";
	}

	@Override
	public String getVersion() {
		return "1.0";
	}
	
	@Override
	public void init(ModelManager manager) throws BasicException {
		 super.init(manager);
		 PluginManager pmf=manager.getPluginManager();
		 PluginManagerUtil pmg = new PluginManagerUtil(pmf);
		 
		 Collection<I_CustomerDebtProcesser> customerDebtProcessers=pmg.getPlugins(I_CustomerDebtProcesser.class);
		 Collection<I_ProductRecommend> productRecommends=pmg.getPlugins(I_ProductRecommend.class);
		 Collection<I_OrderProcessFlow> orderProcessFlows=pmg.getPlugins(I_OrderProcessFlow.class);
		 Collection<I_OrderProcess> orderProcessPlugins=pmg.getPlugins(I_OrderProcess.class);
		 
		 processManager=new OrderProcessManager(orderProcessFlows,orderProcessPlugins);
		 I_Session s=manager.getSession();
		 
		 dlSystem = new DataLogicSystem(s);
         dlERP=new DataLogicERP(s, processManager, customerDebtProcessers, productRecommends);
         dlAdmin=new DataLogicAdmin(s);
         dlCustomers=new DataLogicCustomers(s);		
         dlReceipts=new DataLogicReceipts(s);
	}

	public  I_DataLogicERP getDLERP(){
		return dlERP;
	}
	
	public  I_DataLogic  getDataLogic(){
		return dlERP;
	}
	
	public  I_DataLogicReceipts getDLReceipts(){
		return dlReceipts;
	}
	
	public  I_DataLogicSystem getDLSystem(){
		return dlSystem;
	}
	
	public  I_DataLogicAdmin getDLAdmin(){
		return dlAdmin;
	}
	
	public  I_DataLogicCustomers getDLCustomer(){
		return dlCustomers;
	}

	public I_DataLogicSecurity getDLSecurity() {
		return (I_DataLogicSecurity) dlAdmin;
	}

	@Override
	public Object getBean(String beanfactory) throws BeanFactoryException {
		throw new BeanFactoryException("this model no supered");
	}

	public I_ProcessManager getProcessManager() {
		return processManager;
	}

}
